import storage from "@/utils/storage";
import {
	http,
	Method
} from "@/utils/request.js";
/**
 * 实名认证
 */
export function PostAuthentication(params) {
	return http.request({
		url: "/members/authentication",
		method: Method.POST,
		params,
		needToken: true
	});
}
/**
 * 判断是否设置过密码
 */
export function getPassword(params) {
	return http.request({
		url: "/members/getPaymentPwd",
		method: Method.POST,
		needToken: true
	});
}

// 修改、忘记支付密码
export function PaymentPassword(params) {
	return http.request({
		url: "/members/setPaymentPwd",
		method: Method.POST,
		data: params,
		needToken: true
	});
}

// 设置支付密码
export function PostmentPassword(params) {
	return http.request({
		url: "/members/initPaymentPwd",
		method: Method.POST,
		params,
		needToken: true
	});
}

/**
 * 商家有没有缴纳年费
 */
export function GetStoreFeeStatus() {
	return http.request({
		url: "/store/getStoreFeeStatus",
		method: Method.GET,
		needToken: true
	});
}
/**
 * 商家年费
 */
export function ShopMoney() {
	return http.request({
		url: "/store/get/detail",
		method: Method.GET,
		needToken: true
	});
}

/**
 * 获取商家个人信息
 */
export function GetStoreInfo(id) {
	return http.request({
		url: "/members/sign/getInfo/" + id,
		method: Method.GET,
		needToken: true,
	});
}
/**
 * 获取商家个人信息
 */
export function GetStoreInfoState(id) {
	return http.request({
		url: "/members/sign/getOpenStoreById/" + id,
		method: Method.GET,
		needToken: true,
	});
}
/**
 * 获取商家入驻登录状态
 */
export function GetStoreStatus() {
	return http.request({
		url: "/store/getStoreStatus",
		method: Method.GET,
		needToken: true,
	});
}
/**
 * 获取汇率
 */
export function RateSetting(params) {
	return http.request({
		url: "/cashier/grade",
		method: Method.GET,
		needToken: true,
		params,
	});
}
/**
 * 获取天使合伙人汇率
 */
export function TSRateSetting(params) {
	return http.request({
		url: "/cashier/rateSetting",
		method: Method.GET,
		needToken: true,
		params,
	});
}
/**
 * 会员折扣
 */
export function VIPRateSetting(params) {
	return http.request({
		url: "/rateSetting/member",
		method: Method.POST,
		params,
	});
}
/**
 * 意见反馈
 */
export function feedBack(params) {
	return http.request({
		url: "/feedback",
		method: Method.POST,
		needToken: true,
		params,
	});
}
/**
 * 判断是否申请过注销合伙人
 */
export function SubmittedCancellation(params) {
	return http.request({
		url: "/members/revokePartnerVerify",
		method: Method.POST,
		needToken: true
	});
}
// 注销合伙人申请页面
export function cancellation() {
  return http.request({
    url: '/members/revokePartnerPage',
    method: Method.POST,
    needToken: true,
  });
}

// 注销申请按钮
export function cancellationButton(params) {
  return http.request({
    url: '/members/applyRevokePartner',
    method: Method.GET,
    needToken: true,
    params,
  });
}

// 注销审核进度详情页
export function cancellationPage() {
  return http.request({
    url: '/members/applyRevokePage',
    method: Method.GET,
    needToken: true,
  });
}

// 注销撤回提交
export function cancellationSubmit(params) {
  return http.request({
    url: '/members/applyRevoke',
    method: Method.GET,
    needToken: true,
    params,
  });
}


// 提现
export function withdrawalApply(params) {
	return http.request({
		url: "/members/wallet/withdrawal",
		method: Method.POST,
		needToken: true,
		params,
	});
}

/**
 * 扫码支付
 */
export function paysmzf(params) {
	return http.request({
		url: "/cashier/paysmzf",
		method: Method.POST,
		needToken: true,
		params,
	});
}

/**
 * 支付结果查询
 * @param orderType 交易类型,可用值:TRADE,ORDER,RECHARGE
 * @param sn   订单编号
 */
export function payCallback(params) {
	return http.request({
		url: `/cashier/result`,
		method: Method.GET,
		params,
	});
}

// 在线充值
export function Recharge(params) {
	return http.request({
		url: "/trade/recharge",
		method: Method.POST,
		params: {
			...params,
			owner: 'RECHARGE'
		},
	});
}
// 升级合伙人或者会员充值
export function CreatePartner(params) {
	return http.request({
		url: "/trade/recharge/createPartner",
		method: Method.POST,
		params,
	});
}

/**
 * 分页获取预存款充值记录
 * @param params
 */
export function getUserRecharge(params) {
	return http.request({
		url: "/member/recharge",
		method: Method.GET,
		needToken: true,
		params,
	});
}
/**
 * 累计推广收益总额
 * @param params
 */
export function GetCommission(params) {
	return http.request({
		// url: "/members/wallet/getCommission",
		url: "/members/wallet",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 分页获取预存款充值记录
 * @param params
 */
export function getWalletLog(params) {
	return http.request({
		url: "/wallet/log",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 获取优惠券列表
 * @param params
 */
export function getCoupons(params) {
	return http.request({
		url: "/promotion/coupon/getCoupons",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 领取优惠券
 * @param couponId
 */
export function receiveCoupons(couponId) {
	return http.request({
		url: `/promotion/coupon/receive/${couponId}`,
		method: Method.GET,
		needToken: true,
	});
}

/**
 * 获取积分明细数据
 * @param params
 * @returns {AxiosPromise}
 */
export function getPointsData(params) {
	return http.request({
		url: "member/memberPointsHistory/getByPage",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 获取我的评论列表
 * @param params
 * @returns {AxiosPromise}
 */
export function getComments(params) {
	return http.request({
		url: "/memberEvaluation",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 获取当前会员的浏览数量是多少
 * @param params
 * @returns {AxiosPromise}
 */
export function getFootprintNum(params) {
	return http.request({
		url: "/footprint/getFootprintNum",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 订单评论
 * @param params
 */
export function commentsMemberOrder(params) {
	return http.request({
		url: "/memberEvaluation",
		method: Method.POST,
		needToken: true,
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		data: params,
	});
}
/**
 * 店铺评论
 * @param params
 */
export function shopEvaluation(params) {
	return http.request({
		url: "/store/addStoreEvaluation",
		method: Method.POST,
		needToken: true,
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		data: params,
	});
}


/**
 * 追加评论
 * @param params
 */
export function AppendCommentsOrder(params) {
	return http.request({
		url: "members/comments/additional",
		method: Method.POST,
		needToken: true,
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		data: params,
	});
}

// TODO 第一版本暂未实现此功能
/**
 * 商品咨询
 * @param goods_id
 * @param ask_content
 */
export function consultating(goods_id, ask_content, anonymous) {
	return http.request({
		url: "members/asks",
		method: Method.POST,
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		needToken: true,
		data: {
			goods_id,
			ask_content,
			anonymous,
		},
	});
}

/**
 * 获取商品收藏
 * @param params
 * @returns {AxiosPromise}
 */
export function getGoodsCollection(params, type) {
	return http.request({
		url: `/member/collection/${type}`,
		method: Method.GET,
		needToken: true,
		loading: false,
		message: false,
		params,
	});
}

/**
 * 收藏商品
 * @returns {AxiosPromise}
 */
export function collectionGoods(type, id) {
	return http.request({
		url: `/member/collection/add/${type}/${id}`,
		method: Method.POST,
		needToken: true,
	});
}

/**
 * 删除商品收藏
 * @param ids 收藏ID【集合或单个商品ID】
 * @returns {AxiosPromise}
 */
export function deleteGoodsCollection(ids) {
	if (Array.isArray(ids)) {
		ids = ids.join(",");
	}
	return http.request({
		url: `/member/collection/delete/GOODS/${ids}`,
		method: Method.DELETE,
		needToken: true,
	});
}

/**
 * 删除店铺收藏
 * @param store_id
 */
export function deleteStoreCollection(store_id) {
	return http.request({
		url: `/member/collection/delete/STORE/${store_id}`,
		method: Method.DELETE,
		needToken: true,
	});
}

/**
 * 获取商品是否被收藏
 * @param good_id
 */
export function getGoodsIsCollect(type, good_id) {
	return http.request({
		url: `/member/collection/isCollection/${type}/${good_id}`,
		method: Method.GET,
		needToken: true,
		loading: false,
	});
}

/**
 * 收藏店铺
 * @param store_id 店铺ID
 * @returns {AxiosPromise}
 */
export function collectionStore(store_id) {
	return http.request({
		url: "/members/collection/store",
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		method: Method.POST,
		data: {
			store_id
		},
	});
}
/**
 * 查询是否阅读用户协议和隐私权限
 * @param 
 * @returns {AxiosPromise}
 */
export function checkUserAgreement(params) {
	return http.request({
		url: `/article/getRecordSummary`,
		method: Method.GET,
		params
	});
}
/**
 * 插入是否阅读用户协议和隐私权限
 * @param 
 * @returns {AxiosPromise}
 */
export function insertUserAgreement(params) {
	return http.request({
		url: `/article/AddArticleRecordSummary`,
		method: Method.POST,
		data: params
	});
}
/**
 * 获取当前登录的用户信息
 * @returns {AxiosPromise}
 */
export function getUserInfo() {
	let params = {}
	if (storage.getTgCode()) {
		params.extensionCode = storage.getTgCode()
	}
	console.log("extensionCode:" + storage.getTgCode())
	return http.request({
		url: "/members",
		method: Method.GET,
		needToken: true,
		params
	});
}

/**
 * 获取当前用户的预存款
 * @returns {AxiosPromise}
 */
export function getUserWallet() {
	return http.request({
		url: "/members/wallet",
		method: Method.GET,
		needToken: true,
		params: {
			owner: 'RECHARGE'
		}
	});
}

/**
 * 保存用户信息
 * @param params
 * @returns {AxiosPromise}
 */
export function saveUserInfo(params) {
	return http.request({
		url: "/members/editOwn",
		method: Method.PUT,
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		needToken: true,
		data: params,
	});
}

/**
 * 添加发票
 * @param params
 */
export function addReceipt(params) {
	return http.request({
		url: "/trade/receipt",
		method: Method.POST,
		needToken: true,
		params,
	});
}

/**
 * 获取商品评论列表
 * @param goodsId
 * @param params
 */
export function getGoodsComments(goodsId, params) {
	return http.request({
		url: `/memberEvaluation/${goodsId}/goodsEvaluation`,
		method: Method.GET,
		loading: false,
		params,
	});
}

/**
 * 获取商品评论数量统计
 * @param goodsId
 */
export function getGoodsCommentsCount(goodsId) {
	return http.request({
		url: `/memberEvaluation/${goodsId}/evaluationNumber`,
		method: Method.GET,
		loading: false,
	});
}

/**
 * 获取未读消息数量信息
 */
export function getNoReadMessageNum() {
	return http.request({
		url: `members/member-nocice-logs/number`,
		method: Method.GET,
		needToken: true,
	});
}

/**
 * 我的足迹商品/商店列表
 * @param pageNumber  pageSize
 *
 */
export function myTrackGoodsList(params,type) {
	return http.request({
		url: `/${type}`,
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 根据id删除会员足迹
 * @param id
 */
export function deleteHistoryListId(ids) {
	return http.request({
		url: `/footprint/delByIds/${ids}`,
		method: Method.DELETE,
		needToken: true,
	});
}

/**
 * 获取当前会员优惠券列表
 * @param
 */
export function getMemberCoupons(data) {
	return http.request({
		url: `/promotion/coupon/getCoupons`,
		method: Method.GET,
		needToken: true,
		params: data,
	});
}

/**
 * 获取当前会员可使用的优惠券数量
 *
 */
export function getCouponsNum() {
	return http.request({
		url: `/promotion/coupon/getCouponsNum`,
		method: Method.GET,
		needToken: true,
	});
}

/**
 * 获取会员积分VO
 * @param
 */
export function getMemberPointSum() {
	return http.request({
		url: `member/memberPointsHistory/getMemberPointsHistoryVO`,
		method: Method.GET,
	});
}

/**
 * 成为推广员
 * @param
 */
export function BecomeTuiguangyuan() {
	return http.request({
		url: `/partner/joinPartner`,
		method: Method.GET,
	});
}
export function cashierFee() {
	return http.request({
		url: `/cashier/fee`,
		method: Method.GET,
	});
}

/**
 * 分页获取预存款充值记录
 * @param params
 */
export function getWithdrawal(params) {
	return http.request({
		url: "/member/withdrawApply",
		method: Method.GET,
		needToken: true,
		params,
	});
}

/**
 * 撤销
 * @param params
 */
export function getrevoke(params) {
	return http.request({
		url: "/member/withdrawApply",
		method: Method.POST,
		needToken: true,
		params,
	});
}
/**
 * 转账  根据手机号查询收款人信息
 * @param phone
 */
export function GetPayeeInfo(phone) {
	return http.request({
		url: "/member/transfer/" + phone,
		method: Method.GET,
		needToken: true,
	});
}
/**
 * 转账  查询钱包余额
 * @param phone
 */
export function GetZzWalletDetail() {
	return http.request({
		url: "/member/transfer/tradeNativeDetail",
		method: Method.GET,
		needToken: true,
		params: {
			orderType: 'TRADE',
			clientType: 'WECHAT_MP',
			owner: 'RECHARGE'
		}
	});
}
/**
 * 转账  创建转账交易
 * @param phone
 */
export function CreateTransferOrder(params) {
	return http.request({
		url: "/trade/carts/create/transferTrade",
		method: Method.POST,
		needToken: true,
		data: params
	});
}
/**
 * 转账  付款接口
 * @param phone
 */
export function PayTransferOrder(params) {
	return http.request({
		url: "/cashier/pay/WALLET/TRANSFER",
		method: Method.GET,
		needToken: true,
		params
	});
}
/**
 * 转账  明细  根据订单号查询转账结果  
 */
export function TransferDetail(sn) {
	return http.request({
		url: "/member/transfer/detail/" + sn,
		method: Method.GET,
		needToken: true
	});
}
/**
 * 转账列表 转账总金额
 */
export function TransferMoneyAll(params) {
	return http.request({
		url: "/member/transfer/allTransfer",
		method: Method.GET,
		needToken: true,
		data: params
	});
}
/**
 * 转账列表 转账列表
 */
export function TransferList(params) {
	return http.request({
		url: "/member/transfer",
		method: Method.GET,
		needToken: true,
		params
	});
}

// 查询钱包收入、支出
export function logsum(params) {
	return http.request({
		url: "/wallet/log/sum",
		method: Method.GET,
		needToken: true,
		params
	});
}

// 根据用户id或者商家id查询当前用户名称、头像和商家名称头像等信息
export function getUserInfoById(data) {
	return http.request({
		url: "/members/getUserInfoById",
		method: Method.POST,
		needToken: true,
		params:data
	});
}
